package archer.back.models

import io.circe._
import io.circe.generic.auto._
import utils.CirceUtils

import models.CrawlTables._

case class SimpleNodeInfo(
  id: BigInt,
  url: String,
  delayDays: BigInt,
  titleSelector: String,
  timeSelector: String,
  timeFormatter: String,
  treeNodeId: BigInt) {

  def toDBModel =
    NodeInfoRow(
      id = id.toInt,
      url = url,
      delayHours = delayDays.toInt * 24,
      titleSelector = titleSelector,
      timeSelector = timeSelector,
      treeNodeId = treeNodeId.toInt,
      timeFormatter = timeFormatter,
      modifiedTime = new java.sql.Timestamp(new java.util.Date().getTime))

}

object SimpleNodeInfo extends CirceUtils {
  implicit val SimpleNodeInfoObjectEncoder: ObjectEncoder[SimpleNodeInfo] = {
    exportEncoder.instance
  }

  implicit val SimpleNodeInfoDecoder: Decoder[SimpleNodeInfo] = {
    exportDecoder.instance
  }
}
